package com.zhy.userproiver8001.controller;

import com.zhy.pojo.Employee;
import com.zhy.userproiver8001.service.EmployeeService;
import com.zhy.utils.PageTool;
import com.zhy.utils.ResultTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {
    @Autowired
    EmployeeService service;

    @GetMapping("/getAllEmp")
    public ResultTool getAllEmp(@RequestParam(value = "pageNo",required = false) Integer pageNo,
                                @RequestParam(value = "name",required = false) String name,
                                @RequestParam(value = "status",required = false) Integer status){
        PageTool page = new PageTool();
        if (pageNo==null||pageNo<0||pageNo.equals("")){
            pageNo=1;
        }
        page.setPageNo(pageNo);
        page.setPageCount(service.countEmp(name,status));
        page.setPageSize(5);
        page.setPageSum(page.js());
        List<Employee> allEmp = service.getAllEmp(page,name,status);
        return  new ResultTool(200,"",allEmp);
    }
}
